<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cn.ac.cintcm.dataconverge.researcher.domain.*,
java.util.*,com.hs.core.page.PageUtil,com.hs.core.utils.*,cn.ac.cintcm.dataconverge.util.Constants" %>
<%@ page import="cn.ac.cintcm.dataconverge.util.AuthCheck"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

PageUtil pageUtil = (PageUtil)request.getAttribute("pageUtil");
List orgList = (List)request.getAttribute("orgList");
List subjectList = (List)request.getAttribute("subjectList");
int perpageCount = 1;
int currentPage = 1;
List list = null;
String pageStr = "";
if(null != pageUtil){
	list = pageUtil.getPageList();
   pageStr = pageUtil.getPageStr();
   perpageCount = pageUtil.getNumberPerPage();
   currentPage = pageUtil.getCurrentPage();
}
String orderName = (String)request.getAttribute("orderName");
String orderNum = (String)request.getAttribute("orderNum"); 
String status = (String)request.getAttribute("status"); 
String orgId = (String)request.getAttribute("orgId"); 
String subjectId = (String)request.getAttribute("subjectId"); 
String group = (String)request.getAttribute("group"); 
 
%><html>
  <head>
  	<TITLE>科研人员管理</TITLE>
   <link href="<%=basePath%>index/Themes/com/style.css" rel="stylesheet" type="text/css" />
    <script src="<%=basePath%>index/Scripts/Script.js" language="javascript" type="text/javascript"></script>
     <script src="<%=basePath%>js/common.js" language="javascript" type="text/javascript"></script>
    <script src='<%=basePath%>dwr/engine.js'></script>
     <script src='<%=basePath%>dwr/util.js'></script> 
     <script src='<%=basePath%>dwr/interface/subject.js'></script> 
	<SCRIPT type="text/javascript">
	function modifyUser(value) {
	        //var bln = window.confirm("确定要修改吗？", "确定", "取消");
	        //if(bln == true) {
//	        var page=document.all.ec_p.value;
 			var page = 5;
			url = "researcher.htm?action=tomodify&flag=mod&ids=" + value+"&page="+page;
			openwindow(url,'850','600','');
			//}
		} 
	function deleteUser(value) {
	    
		var bln = window.confirm("确定要删除此用户吗？", "确定", "取消"); 
		if(bln == true) {
		    subject.delRes(value,deleteCallback); 
		}
	}
	function deleteCallback(message){ 
		if("0"==message){
		    alert("删除成功");
			submitPageForm();
		} 
		if("1"==message){
		    alert("该人员目前参与了课题，不能删除!");
		}
	}
	var statusStr = "";
	var userStr = "";
	function changeStatus(userName,userId){
	    var status = document.getElementById("userStatus_"+userId).value;
	    if("" == status)
	       return;
	     userStr = userId;  
	    if("N" == status){
	        if(confirm("确定要把【" + userName + "】帐号生效吗?")){
	    		subject.changeStatus(userName,userId,status,callbackForChange);
	    		statusStr = "Y";
	    		document.getElementById("user_"+userId).innerHTML='已生效';
	    		document.getElementById("userStatus_"+userId).value='Y';
	    	}
	    }
	    if("Y" == status){
	        if(confirm("确定要把【" + userName + "】帐号失效吗?")){
	    		subject.changeStatus(userName,userId,status,callbackForChange);
	    		statusStr = "N";
	    		document.getElementById("user_"+userId).innerHTML='待生效';
	    		document.getElementById("userStatus_"+userId).value='N';
	    	}
	    }
	
	}
	function callbackForChange(message){ 
	   alert(message); 
	   //window.location.replace(document.location.href);
	}
	</SCRIPT>
</head>
  
 <body  scroll="yes">
      <div class="r_rtm_tb_mg1">
        <div class="r_rtm_tb1">
            <img src="<%=basePath%>index/Themes/com/idt_tb_pass.gif" />&nbsp;科研人员管理
        </div>
    </div>
     <table cellspacing="2" cellpadding="0" width="100%" class="idt_item_mg" id="Table2">
     <tbody><form name="searchform" action="researcher.htm?action=list" method="post">
        <tr>
		
         <td class="fim_l" width="10%">姓名:</td>
            <td class="fim_r" width="20%">
               <input type="text" class="com_textbox" id="name" name="name" value="<%=StringUtilTool.setObjNULLStr(request.getAttribute("name")) %>"></td>
               <td class="fim_l" width="10%">单位:</td>
            <td class="fim_r" width="40%">
               <select name="orgId" style="width:100%">
                <option value=""></option>
                <%
                 if(orgList.size()>0){ 
                	 for(int i =0;i<orgList.size();i++){
                		 Organization org = (Organization)orgList.get(i);
                		 out.print("<option value=");
                		 out.print(org.getId());
                		 if((org.getId()+"").equals(orgId))
                		 	out.print(" selected");
                		 out.print(">");
                		 out.print(org.getName());
                		 out.print("</option>");
                	 }
                 }
                %>
                </select>
                </td>
                <td class="fim_l" width="10%">用户部门:</td>
            <td class="fim_r">
          	 <input type="text" class="com_textbox" id="nameDep" name="nameDep" value="<%=StringUtilTool.setObjNULLStr(request.getAttribute("nameDep")) %>" >
              </td> 
            <td class="fim_r" align="right" nowrap="nowrap" colspan="4">
                <input type="submit" value="查询" name="B3" class="com_btn2" id="Button5">
                 <input type="button" value="高级查询" name="B3" onclick="if(AdCheckForm.style.display=='none')AdCheckForm.style.display='';else AdCheckForm.style.display='none';"
                    class="com_btn2" id="Button1">
                   <%if(AuthCheck.isHasAuth(request,Constants.AUTHMETHOD_RES_ADD)){ %>
                <input type="button" value="添加" name="B4" class="com_btn2" id="Button2" onclick="javascript:openwindow('researcher.htm?action=addResearcher','850','600','');">
			 <%} %>
            </td>
        </tr>
          <tr id="AdCheckForm" style="display: none;">
           <td class="fim_l">用户ID :</td>
          	<td class="fim_r">
             <input type="text" class="com_textbox" id="ida" name="ida" value="<%=StringUtilTool.setObjNULLStr(request.getAttribute("ida")) %>"></td>
            <td class="fim_l">
                用户组：</td>
            <td class="fim_r">
            
              <select name="group" style="width:100%">
                <option value=""></option>
                 <option value="<%=Constants.HEADMASTER %>" <%if(Constants.HEADMASTER.equals(group)){out.print("selected");} %>>院长组</option>
                 <option value="<%=Constants.SYSTEM_MANAGER %>" <%if(Constants.SYSTEM_MANAGER.equals(group)){out.print("selected");} %>>系统管理员</option>
                 <option value="<%=Constants.LEADER %>" <%if(Constants.LEADER.equals(group)){out.print("selected");} %>>院科研处领导</option>
                 <option value="<%=Constants.ORG_LEADER %>" <%if(Constants.ORG_LEADER.equals(group)){out.print("selected");} %>>所科研处领导</option> 
                 <option value="<%=Constants.RESEARCHER %>" <%if(Constants.RESEARCHER.equals(group)){out.print("selected");} %>>科研人员</option>
                 <option value="<%=Constants.EXPERT %>" <%if(Constants.EXPERT.equals(group)){out.print("selected");} %>>专家评审组</option>
                </select> 
	
             </td>
            <td class="fim_l">
                  学科角色：</td>
            <td class="fim_r" colspan=3>
                <select name="subjectId" style="width:100%">
                <option value=""></option>
                <%
                 if(subjectList.size()>0){ 
                	 for(int j =0;j<subjectList.size();j++){
                		 SystemDict dict = (SystemDict)subjectList.get(j);
                		 out.print("<option value=");
                		 out.print(dict.getId());
                		 if((dict.getId()+"").equals(subjectId))
                		 	out.print(" selected");
                		 out.print(">");
                		 out.print(dict.getName());
                		 out.print("</option>");
                	 }
                 }
                %>
                </select></td>
                
		<td class="fim_l">用户状态:</td>
            <td class="fim_r">
            <select name="status" >
            <option value="">--请选择--</option>
            <option value="N" <%if("N".equals(status)){out.println(" selected");} %>>待生效</option>
             <option value="Y" <%if("Y".equals(status)){out.println(" selected");} %>>已生效</option>
            </select>
              </td>
        </tr>
        </form></tbody>
    </table>
    <div class="content">
        <table width="*" cellpadding="0" cellspacing="1" class="dg_borderstyle" id="Table4" >
            <tr>
                <td class="dg_headerstyle">
                    序号</td>
                <td class="dg_headerstyle" ><a href="javaScript:orderPage('ida','<%=OrderTool.getOrderNum("ida",orderName,orderNum)%>');">用户名&nbsp;&nbsp;<%=OrderTool.getOrderImage(basePath,OrderTool.getOrderNum("ida",orderName,orderNum))%></a></td>
                <td class="dg_headerstyle">
                 <a href="javaScript:orderPage('name','<%=OrderTool.getOrderNum("name",orderName,orderNum)%>');">姓名&nbsp;&nbsp;<%=OrderTool.getOrderImage(basePath,OrderTool.getOrderNum("name",orderName,orderNum))%></a></td>
                <td class="dg_headerstyle">
                  用户组 </td>
                    
                      <td class="dg_headerstyle">
               <a href="javaScript:orderPage('org.id','<%=OrderTool.getOrderNum("org.id",orderName,orderNum)%>');">单位&nbsp;&nbsp;<%=OrderTool.getOrderImage(basePath,OrderTool.getOrderNum("org.id",orderName,orderNum))%></a></td>
                    
                    
                     <td class="dg_headerstyle">
               <a href="javaScript:orderPage('department.id','<%=OrderTool.getOrderNum("department.id",orderName,orderNum)%>');">部门&nbsp;&nbsp;<%=OrderTool.getOrderImage(basePath,OrderTool.getOrderNum("department.id",orderName,orderNum))%></a></td>
                    
                    
                      <td class="dg_headerstyle">
               <a href="javaScript:orderPage('position','<%=OrderTool.getOrderNum("position",orderName,orderNum)%>');">学科角色&nbsp;&nbsp;<%=OrderTool.getOrderImage(basePath,OrderTool.getOrderNum("position",orderName,orderNum))%></a></td>
                    
                      <td class="dg_headerstyle">
                 <a href="javaScript:orderPage('idcard','<%=OrderTool.getOrderNum("idcard",orderName,orderNum)%>');">身份证号&nbsp;&nbsp;<%=OrderTool.getOrderImage(basePath,OrderTool.getOrderNum("idcard",orderName,orderNum))%></a></td>
                   <td class="dg_headerstyle">
                 <a href="javaScript:orderPage('status','<%=OrderTool.getOrderNum("status",orderName,orderNum)%>');">当前状态&nbsp;&nbsp;<%=OrderTool.getOrderImage(basePath,OrderTool.getOrderNum("status",orderName,orderNum))%></a></td>
                <td class="dg_headerstyle">编辑</td>
                 <td class="dg_headerstyle">删除</td>
            </tr>
            <% 
            if(null!= list && list.size()>0){
            	Iterator iterator = list.iterator(); 
            	int i=0;
            	while(iterator.hasNext()){
           		   Researcher researcher = (Researcher)iterator.next();
           		   i++;
            %>
            <tr class="dg_alternatingitemstyle" onmouseover="ChangeRowBg(this);" onmouseout="ChangeRowBg(this);" onmouseup="ChangeRowBg(this);" onmousedown="ChangeRowBg(this);">
                <td align="center">
                    <%= perpageCount*(currentPage-1)+i %></td>
                <td>
                    <%=researcher.getIda() %>
                </td>
                <td>
                    <a href="javaScript:openwindow('<%=path %>/index/loginEdit.jsp?uid=<%=researcher.getIds() %>','500','400','');"><span id="name_<%=researcher.getIds() %>"> <%=researcher.getName() %></span></a>
                    
                </td>
                
                   <td>
                    <span id="group_<%=researcher.getIds() %>"> <%
                       Set groupSet = researcher.getGroups();
                       Iterator iter = groupSet.iterator();
                       int j=0;
                       while(iter.hasNext()){
                    	   ResmanUserGroup g = (ResmanUserGroup)iter.next();
                    	   if(null != g && g.getGroup()!=null){ 
                    		   out.print(g.getGroup().getGroupname());
                    		   out.print("&nbsp;");
                    	   } 
                    		   
                       }
                     
                     %></span>
                </td>
                
                   <td>
                    <span id="org_<%=researcher.getIds() %>"> <%if(researcher.getOrg() != null)out.print(researcher.getOrg().getName()); %></span>
                </td>
                
                   <td>
                     <span id="dept_<%=researcher.getIds() %>"><%if(researcher.getDepartment() != null)out.print(researcher.getDepartment().getName()); %></span>
                </td>
                
                   <td>
                    <span id="postion_<%=researcher.getIds() %>"> <%=Constants.getPosition(researcher.getPosition())%></span>
                </td>
                
                   <td>
                     <span id="idcard_<%=researcher.getIds() %>"><%=StringUtilTool.setObjNULLStr(researcher.getIdcard()) %></span>
                </td>
                <td align="center">
                 <font color="red">
                  <a href="javaScript:changeStatus('<%=researcher.getIda()%>','<%=researcher.getIds()%>');">
                  <input type="hidden" value="<%=researcher.getStatus()%>"  id="userStatus_<%=researcher.getIds()%>"/>
                   <span id="user_<%= researcher.getIds()%>">
                  
                     <% 
                        if("N".equals(researcher.getStatus()))
                        	 out.println("待生效");
                        if("Y".equals(researcher.getStatus()))
                    	     out.println("已生效");
                     
                     %></span></a>
                     </font>
                </td> 
                <td align="center">
                  <%if(AuthCheck.isHasAuth(request,Constants.AUTHMETHOD_RES_MOD)){ %>
                <img style="cursor: hand" src="<%=basePath%>index/Themes/com/68design.net_registration1_(edit)_16x16.gif" onclick="javascript:modifyUser('<%=researcher.getIds() %>');"
                                    alt="编辑" />
                                    <%} %>
                <td align="center">
                  <%if(AuthCheck.isHasAuth(request,Constants.AUTHMETHOD_RES_DEL)&&!"system".equals(researcher.getIda())){ %>
                <img style="cursor: hand" src="<%=basePath%>index/Themes/com/68design.net_registration1_(delete)_16x16.gif" onclick="deleteUser('<%=researcher.getIds() %>');"
               alt="删除" />
               <%} %>
                </td>
            </tr>
            <%} }else{%>
             <tr class="dg_alternatingitemstyle">
                 <td colspan="11" align="center"><font color="red">没有记录</font></td>
            </tr> 
            <%} %>
        </table>
        <div class="dg_pagerstyle" align="right">
        <%=pageUtil.getPageStr()%>
        </div>
    </div>
  </body>
</html>
